Agenda * search related options * search commands * regular expressions * substitution # search related options :set incsearch search incrementally :set hlsearch highlight search matches :set nohlsearch permanently clear highlighting :nohlsearch clear current highlighting :set ignorecase disable search case sensitivity :set smartcase auto detect case sensitivity # search commands / shortcuts * find word under cursor # find word under cursor (backwards) / find pattern ? find pattern (backwards) n next match N previous match # regular expressions \| logical or [ ... ] character class, e.g. [abc] [a-z] [A-Z] [^ ... ] character class (inverse), e.g. [^abc] \d [0-9] digit \a [a-zA-Z] alphabet character \w [0-9a-zA-Z_] word character \s whitespace character ( and ) \D [^0-9] non-digit character \A [^a-zA-Z] non-alphabet character \W [^0-9a-zA-Z_] non-word character \S non-whitespace character ( or ) . any character \{char} escape magic character * 0 or more occurrences \+ 1 or more occurrences \? 0 or one occurrences \{n} exactly n occurrences \{n,m} n up to m occurrences \{,m} 0 to m occurrences \{n,} n or more occurrences ^ start of line anchor $ end of line anchor \< start of word boundary \> end of word boundary \zs start of match \ze end of match \( ... \) grouping \v very magic mode \V very nomagic mode \c ignore case for this pattern \C force case sensitivity for this pattern # substitute command :{range}s[ubstitute]/{pattern}/{replacement}/{flags} :%s/{pattern}/{replacement}/g replace all occurrences :s/// :s::: :s;;; :s### :s+++ :s@@@ some options for separators # flags g global substitution i ignore case c confirmation mode n count matches # replacements for substitute ~ the previous replacement & the whole match \0 the whole match (also called group 0) \[n] capturing group [n] \~ a literal tilde '~' \& a literal ampersand '&' \\ a literal backslash '\' # examples : s/student/teacher/ replace one occurrence on current line :3,9 s/student/teacher/ replace one occurrence from line 3 up to line 9 :% s/student/teacher/ replace one occurrence on every line :% s/student/teacher/g replace every occurence :% s/student/teacher/gc confirm every occurrence # shorthands :s on current line, reuse search & replacement :s/// on current line, reuse search and delete the match :& repeat last substitution on current line :&& repeat last substitution on current line, reuse flags :%& repeat last substitution on all lines :%&& repeat last substitution on all lines, reuse flags :%&g repeat last substitution on all lines, use global flag # relevant help pages :help pattern.txt everything related to search :help :s substitute command :help range specifying a range for an ex-command :help s_flags these flags can be used with :substitute :help \0 escape sequences in replacements